(function () {
    console.log("煤粉分配率文件");
    let now_open_diag = {}
    now_open_diag.API_URL = ' '
    //创建一个三维场景
    document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
    const devicePixelRatio = window.devicePixelRatio;//设备分辨率
    let rsqState = [0, 0, 0, 0]
    let arrbox = []
    let initdatashishi = null
    const initdata = () => {
        clearInterval(initdatashishi)
        req.get('/api/sjdl/home/point/value').then(res => {
            let obj = {}
            Object.keys(res.data).sort().forEach(item => {
                obj[item] = res.data[item];
                //执行的回调函数
            })
            arrbox = []
            for (let key in obj) {
                arrbox.push(Number(obj[key].FPL).toFixed())
            }
            console.log(arrbox)
            let oIndexDiv = document.getElementsByClassName("wendutiao_react nomal")
            for (var index = 0; index < arrbox.length; index++) {
                //
                let iValue = arrbox[index]
                // console.log(document.getElementById(idZh).value, );
                if (rsqState[0] == 1) {
                    if (index <= 3) {
                        iValue = 0
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = "green"
                    }
                } else {
                    if (index <= 3) {
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
                    }

                }
                if (rsqState[1] == 1) {
                    if (index <= 7 && index > 3) {
                        iValue = 0
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = "green"
                    }
                } else {
                    if (index <= 7 && index > 3) {
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
                    }

                }
                if (rsqState[2] == 1) {
                    if (index <= 11 && index > 7) {
                        iValue = 0
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = "green"
                    }
                } else {
                    if (index <= 11 && index > 7) {
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
                    }

                }
                if (rsqState[3] == 1) {
                    if (index <= 15 && index > 11) {
                        iValue = 0
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = "green"
                    }
                } else {
                    if (index <= 15 && index > 11) {
                        iValue > 50 ? iValue = 50 : ""
                        oIndexDiv[index].style.height = iValue * 2 + "%"
                        oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
                    }

                }

            }
            initdatashishi = setInterval(() => { initdata() }, 3000)
            removeLoader('加载中....')
        })
    }
    // let shishichongzhi = null
    // const initDataFromINnput = () => {
    //     clearInterval(shishichongzhi)
    //     //重置数据
    //     // 获取输入框值
    //     // 获取输入框值  5 6  8 9  11 12  14 15  17 18  20 21   23 24
    //     req.post('/spf/visit/getThermalFieldAll').then(res => {
    //         rsqState[0] = res.data.runStateA
    //         rsqState[1] = res.data.runStateB
    //         rsqState[2] = res.data.runStateC
    //         rsqState[3] = res.data.runStateD
    //         let oIndexDiv = document.getElementsByClassName("wendutiao_react nomal")
    //         for (var index = 0; index < arrbox.length; index++) {
    //             //
    //             let iValue = arrbox[index]
    //             // console.log(document.getElementById(idZh).value, );
    //             if (rsqState[0] == 1) {
    //                 if (index <= 3) {
    //                     iValue = 0
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = "green"
    //                 }
    //             } else {
    //                 if (index <= 3) {
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
    //                 }

    //             }
    //             if (rsqState[1] == 1) {
    //                 if (index <= 7 && index > 3) {
    //                     iValue = 0
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = "green"
    //                 }
    //             } else {
    //                 if (index <= 7 && index > 3) {
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
    //                 }

    //             }
    //             if (rsqState[2] == 1) {
    //                 if (index <= 11 && index > 7) {
    //                     iValue = 0
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = "green"
    //                 }
    //             } else {
    //                 if (index <= 11 && index > 7) {
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
    //                 }

    //             }
    //             if (rsqState[3] == 1) {
    //                 if (index <= 15 && index > 11) {
    //                     iValue = 0
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = "green"
    //                 }
    //             } else {
    //                 if (index <= 15 && index > 11) {
    //                     iValue > 50 ? iValue = 50 : ""
    //                     oIndexDiv[index].style.height = iValue * 2 + "%"
    //                     oIndexDiv[index].style.background = iValue > 37.5 ? "green" : iValue < 12.5 ? "green" : "green"
    //                 }

    //             }

    //         }
    //         shishichongzhi = setInterval(() => { initDataFromINnput() }, 500)
    //         removeLoader('加载中....')
    //     })
    // }
    function Request(baseUrl = '', time = 1000) {
        this.baseUrl = baseUrl;

        function request(url, option = {}) {
            return new Promise(async (resolve, reject) => {
                try {
                    const response = await fetch(baseUrl + url, option);
                    if (response.status == '200') {
                        const data = await response.json();
                        if (data.code == '200') {
                            resolve(data);
                        } else {
                            reject(data.message || '请求失败');
                        }
                    } else {
                        reject(response);
                    }
                } catch (e) {
                    reject(e);
                }
            })
        }

        this.post = function (url, data) {
            return request(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
        }

        this.get = function (url) {
            return request(url, {
                method: 'GET'
            })
        }
    }


    Request.createRequest = function (baseUrl) {
        return new Request(baseUrl);
    }

    const req = Request.createRequest(now_open_diag.API_URL);
    const initEvent = (str) => {//
        //获取事件元素
        let oFootBtns = document.getElementById(str).children //底部菜单 btns
        if (str == "zbf_foot_btns") {
            now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 1].style.display = "none"
            // now_open_diag.username == "admin" ? "" : oFootBtns[oFootBtns.length - 2].style.display = "none"
        }
        for (let i = 0; i < oFootBtns.length; i++) {
            oFootBtns[i].onclick = () => {
                for (let ii = 0; ii < oFootBtns.length; ii++) {
                    oFootBtns[ii].className = ""
                }
                oFootBtns[i].className = "active"
                if (str == "zbf_r_btns") {
                    if (i == 8) {
                        for (let o = 6; o < 14; o++) {
                            scene.children[2].children[o].visible = false
                        }
                    } else {
                        scene.children[2].children[13 - i].visible = !scene.children[2].children[13 - i].visible
                    }
                } else {
                    function closeDiag() {
                        frist ? clearInterval(frist) : ""
                        // timer ? clearInterval(timer) : ""
                        oTodayTimer ? clearInterval(oTodayTimer) : ""

                    }
                    switch (i) {
                        case 0:
                            closeDiag()
                            setTimeout(() => {
                                window.location.href = "/index.html"
                            }, 200)
                            break;
                        case 1:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("全炉膛温度场", 11, "SJDL_IFS_DATA.prj", "全炉膛温度场")
                                window.location.href = "/quanlutang.html"
                            }, 200)

                            break;
                        case 2:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("横截面", 6, "SJDL_IFS_DATA.prj", "横截面")
                                window.location.href = "/hjm.html"
                            }, 200)

                            break;
                        case 3:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("燃烧稳定性监测", 7, "SJDL_IFS_DATA.prj", "燃烧稳定性监测")
                                window.location.href = "/ranshaowendingxing.html"
                            }, 200)

                            break;
                        case 4:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉分配率", 9, "SJDL_IFS_DATA.prj", "煤粉分配率")
                                window.location.href = "/meifen.html"
                            }, 200)

                            break;
                        case 5:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("煤粉颗粒度分布", 8, "SJDL_IFS_DATA.prj", "煤粉颗粒度分布")
                                window.location.href = "/main/dcimgs/gl/main.html"
                            }, 200)

                            break;
                        case 6:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警信息", 12, "SJDL_IFS_DATA.prj", "预警信息")
                                window.location.href = "/yujing.html"
                            }, 200)

                            break;
                        case 7:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("历史数据", 10, "SJDL_IFS_DATA.prj", "历史数据")
                                window.location.href = "/history.html"
                            }, 200)

                            break;
                        case 8:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("历史数据", 10, "SJDL_IFS_DATA.prj", "历史数据")
                                window.location.href = "/dcsHistory.html"
                            }, 200)
                            break;
                        case 9:
                            closeDiag()
                            setTimeout(() => {
                                // openFM("预警阈值配置修改", 14, "SJDL_IFS_DATA.prj", "预警阈值配置修改")
                                window.location.href = "/canshushezhi.html"
                            }, 200)

                            break;
                        default:

                    }

                }
            }
        }
    }

    initEvent('zbf_foot_btns') //底部菜单 btns
    // let c_form = eval('formview_' + now_open_diag.fmname)
    // c_form.onready = function () {// 页面打开 数据加载完成
    //     initDataFromINnput()
    // }
    lsLoader('加载中....')
    let frist = setInterval(() => {
        initdata()
        // initDataFromINnput()
        clearInterval(frist)
    }, 500)
    let oTodayTimer = setInterval(() => {
        document.getElementById("todayTimer").innerHTML = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
    }, 1000)


})()
